import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:part_time_job_pro/common/routers/names.dart';
import 'package:part_time_job_pro/common/store/config.dart';
import 'package:part_time_job_pro/common/utils/common.dart';

/// 第一次欢迎页面
class RouteSplashMiddleware extends GetMiddleware {
  // priority 数字小优先级高
  @override
  int? priority = 0;

  RouteSplashMiddleware({required this.priority});

  @override
  RouteSettings? redirect(String? route) {
    if (ConfigStore.to.isFirstOpen == true) {
      return null;
    } else if (CommonUtil.isLogined() == true) {
      //进入首页
      return const RouteSettings(name: AppRoutes.homePage);
    } else {
      //进入登录
      return const RouteSettings(name: AppRoutes.userLogin);
    }
  }
}
